﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestAjax.aspx.cs" Inherits="iBet.TestPages.TestAjax" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../js/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
	<!-- <script src="../js/test/default.js" type="text/javascript"></script> -->
	<%--<script src="../js/test/noobs.js" type="text/javascript"></script>--%>
	<script type="text/javascript" >
	    var varType;
	    var varUrl;
	    var varData;
	    var varContentType;
	    var varDataType;
	    var varProcessData;
	    //Generic function to call AXMX/WCF  Service        
	    function CallService() {
	        $.ajax({
	            type: varType, //GET or POST or PUT or DELETE verb
	            url: varUrl, // Location of the service
	            data: varData, //Data sent to server
	            contentType: varContentType, // content type sent to server
	            dataType: varDataType, //Expected data format from server
	            processdata: varProcessData, //True or False
	            success: function(msg) {//On Successfull service call
	                ServiceSucceeded(msg);
	            },
	            error: ServiceFailed// When Service call fails
	        });
	    }

	    function ServiceSucceeded(result) {//When service call is sucessful
	        alert(result);
	    }
	    function ServiceFailed(result) {
	        alert('Service call failed: ' + result.status + '' + result.statusText);
	        varType = null; varUrl = null; varData = null; varContentType = null; varDataType = null; varProcessData = null;
	    }

	    function TestCalculation() {
	        varType = "POST";
	        varUrl = "http://localhost:8008/Services/TicketCalculator.svc/TestCalculation";
	        varData = '{"input": "2.0"}';
	        //varData = '{"test": "2.0"}';
	        varContentType = "application/json; charset=utf-8";
	        varDataType = "json";
	        varProcessData = true;
	        CallService();
	    }
	</script>
	<link href="../css/style.css" type="text/css" rel="stylesheet" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="button" value="Invoke" id="btnInvokeWCFJSON" onclick="TestCalculation();" />        
    </div>
    </form>
</body>
</html>
